<template>
  <section class="mui-content">
    <div id="bcid">
      <div style="height:40%"></div>
      <p class="tip">载入中...</p>
    </div>
    <footer @tap='goBack'>
      <div class="fbt mui-action-back">取 消</div>
    </footer>
  </section>
</template>

<script>
  import {MH_API} from "@/api/api";

  let scan = null;
  export default {
    name: "scancode",
    data () {
      return {
        codeFlag: true
      }
    },
    created () {
      MH_API.activeSign({
        id: '102438101'
      }).then(res => {
        if (res.status == 200) {

        }
      })
    },
    methods: {
      goBack(){
        scan.close();
        this.$router.go(-1)
      },
      // 二维码扫描成功
      onmarked(type, result, file) {
        switch(type) {
          case plus.barcode.QR:
            type = 'QR';
            break;
          case plus.barcode.EAN13:
            type = 'EAN13';
            return;
          case plus.barcode.EAN8:
            type = 'EAN8';
            return;
          default:
            type = '其它' + type;
            return;
        }
        console.log(result)
        console.log(JSON.stringify(result))
        //scan.close();
        //var parames = this.getQueryString(result);
      },
      getQueryString(url) {
        var obj = {}
        var reg = /[?&][^?&]+=[^?&]+/g
        var arr = url.match(reg)
        // ['?id=12345','&a=b']
        if (arr) {
          arr.forEach(function(item){
            var tempArr = item.substr(1).split('=')
            var key = decodeURIComponent(tempArr[0])
            var val = decodeURIComponent(tempArr[1])
            obj[key] = Number(val);
          })
        }
        return obj
      }
    },
    components: {

    },
    mounted(){
      let self = this;
      mui.plusReady(function () {
        scan = new plus.barcode.Barcode('bcid');
        scan.onmarked = self.onmarked;
        scan.start({
          conserve: true,
          filename: '_doc/barcode/'
        });
      })
    }
  }
</script>

<style lang="scss" scoped>
  body {
    margin: 0;
    padding: 0;
  }
  .mui-content{ background-color:#000; height:100%;}
  #bcid {
    width: 100%;
    position: absolute;
    top: 0px;
    bottom: 44px;
    text-align: center;
  }

  .tip {
    color: #fff;
    font-weight: bold;
    text-shadow: 0px -1px #103E5C;
  }

  footer {
    width: 100%;
    height: 44px;
    position: absolute;
    bottom: 0px;
    line-height: 44px;
    text-align: center;
    color: #FFF;
  }

  .fbt {
    width: 100%;
    height: 100%;
    background-color: #e685aa;
  }
</style>
